#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;

int a[10]={1,2,3,4,5,6,7,8,9};
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)a[i]=i;
	
	do{
		for(int i=1;i<=n;i++){
			cout<<setw(5)<<a[i];
		}
		cout<<endl;
	}while(next_permutation(a+1,a+n+1)); 
	return 0;
} 
